// pages/appointmentDetail/appointmentDetail.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

    lid: '', //理发师ID
    fname:'' //理发师
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getappoint()
    that.data.lid = options.lid;
    // that.data.fname = options.fname;
    // console.log("美发店+:" + options.dname)
    wx.request({
      url: app.globalData.headurl + '/Lfdlifashi/selectLfdlifashiById',
      data: {
        lid: options.lid
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
        //token: app.globalData.token
      },
      success: function (r) {
        that.setData({
          lfdlifashi: options.fname,
          dname: options.dname

        })
      }
    })

    wx.request({
      url: app.globalData.headurl + '/Lfdcomment/selectLfdcommentByLid',
      data: {
        lid: options.lid
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
        //token: app.globalData.token
      },
      success: function (r) {
        that.setData({
          lfdcommentlist: r.data
        })
      }
    })

    wx.request({
      url: app.globalData.headurl + '/Lfdappoint/selectLfdappointByLid',
      data: {
        lid: options.lid
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
        //token: app.globalData.token
      },
      success: function (re) {
        // var bnum = 0;
        // var gnum = 0;
        console.log("该理发师的订单数量：", re.data.length);
        var lfshiapoointNum = re.data.length
        var dnum = lfshiapoointNum*60;
        console.log("该理发师完成订单需要的时间：", dnum);
        // for (var i = 0; i < re.data.length; i++) {
        //   if (re.data[i].xingbie == '男') {
        //     bnum = bnum + 20
        //   }
        //   if (re.data[i].xingbie == '女') {
        //     gnum = gnum + 70
        //   }

        // }

        that.setData({
          lfdappointnum: re.data.length,
          dnum: dnum
        })
      }
    })




  },
   //获取所有预约订单信息
   getappoint:function(){
    var that =this
    wx.request({
      url: app.globalData.headurl + '/Lfdappoint/selectLfdappointByOpenid',
      data: {
        openid: app.globalData.openid
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
      },
      success: function (re) {
        that.data.lfdappointlist = re.data
        console.log("订单",that.data.lfdappointlist)
         var fList = that.getTrueTime(that.data.lfdappointlist)
        that.setData({
          lfdappointlist: re.data.reverse(),
          fList:fList
        })
      }
    })
  },
  //获取系统中该理发师已有的订单
  getTrueTime:function(tList){
    // var that = this
    // console.log("全部订单",that.data.lfdappointlist)
    var tList = tList
    var newfid = this.data.lid;
    console.log("选择id",newfid)
    console.log("全部订单",tList.length)
    var newarr = []
    for(let i=0;i<tList.length;i++){
      var p = tList[i]
      if(tList[i].lid == newfid){
        newarr.push(p)
      }
    }
    return newarr
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})